// import config from './config'
const {host, mobileHost, localCookie} = require('./config')

export default (url, data = {}, method = 'GET') => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: host + url,
      data,
      method,
      header: {
        cookie:wx.getStorageSync('cookies').toString()||localCookie
      },
      success: (res) => {
        if(data.isLogin) {
          wx.setStorage({
            key:'cookies',
            data:res.cookies
          })
        console.log(url,data,res);
        }
        resolve(res.data)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}